package com.wfd.service;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;

public class ExcelWriteTest {

    public void writeTest1() throws FileNotFoundException {

        String  path = "D:\\study test\\ExcelDemo";

        //创建一个03版的工作簿
        Workbook workbook = new HSSFWorkbook();
        //创建一个工作表
        Sheet sheet = workbook.createSheet("3.20号");
        //创建一个行(0),0代表第一行,以此往下类推
        Row row1 = sheet.createRow(0);
        //创建第一行第一个单元格,0代表第一列,第0行第0列就代表第一行第一个单元格
        Cell  cell1_1 = row1.createCell(0);
        //往单元格中添加内容
        cell1_1.setCellValue("客户");
        //创建第一行第二个单元格
        Cell cell1_2 = row1.createCell(1);
        cell1_2.setCellValue("产品");

        //也可以直接创建单元格
        Row row2 = sheet.createRow(1);
        Cell cell2_1 = row2.createCell(0);
        cell2_1.setCellValue("德正汽配");
        Cell cell2_2 = row2.createCell(1);
        cell1_2.setCellValue("索纳塔后片");

        //存放时间
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Cell cell1_3 = row1.createCell(2);
        cell1_3.setCellValue(simpleDateFormat.format(date));

        //注意：03版一定要用xls后缀名
        FileOutputStream outputStream = new FileOutputStream(path+"03版Excel_demo.xls");

    }
}
